package info.niwota.start.app;

import info.niwota.start.ResourceInfo;
import android.content.ComponentName;
import android.content.Intent;
import android.graphics.drawable.Drawable;

class ApplicationInfo implements ResourceInfo {

	boolean filtered; // image resized

	Drawable icon;
	
	String id;
	
	Intent intent;

	String title;

	int type = Types.ALL;
	
	int iconResId;
	
	long rowId;

	@Override
	public boolean equals(Object o) {
		if (this == o) {
			return true;
		}
		if (!(o instanceof ApplicationInfo)) {
			return false;
		}

		ApplicationInfo that = (ApplicationInfo) o;
		
		return title.equals(that.title)
				&& intent.getComponent().getClassName().equals(
						that.intent.getComponent().getClassName());
	}

	@Override
	public int hashCode() {
		int result;
		result = (title != null ? title.hashCode() : 0);
		final String name = intent.getComponent().getClassName();
		result = 31 * result + (name != null ? name.hashCode() : 0);
		return result;
	}

	final void setActivity(ComponentName className, int launchFlags) {
		intent = new Intent(Intent.ACTION_MAIN);
		//intent.addCategory(Intent.CATEGORY_LAUNCHER);
		intent.setComponent(className);
		intent.setFlags(launchFlags);
	}

	public Drawable getIcon() {
		return icon;
	}

	public Intent getIntent() {
		return intent;
	}

	public String getTitle() {
		return title;
	}

	public String getId() {
		return id;
	}

	public int getIconResId() {
		return iconResId;
	}

	public long getRowId() {
		return rowId;
	}

	@Override
	public String toString() {
		return title;
	}
}
